package com.niit.controller;


import com.niit.entity.Product;
import com.niit.service.impl.ProductServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api")
public class APIController {

    @Autowired
    private ProductServiceImpl productServiceImpl;

    @RequestMapping("/{productId}")
    public String getProductDetails(@PathVariable Integer productId) {
        Product product = productServiceImpl.selectProductById(productId);
        return "{\"productId\":\"" + product.getId() + "\",\"name\":\"" + product.getName() +"\",\"price\":\"" +product.getPrice() +"\",\"stock_quantity\":\"" + product.getStockQuantity() + "\" }";
    }
}
